package com.preguicoso.client.estabelecimento.carrinho;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Widget;
import com.preguicoso.client.estabelecimento.cardapio.CardapioService;
import com.preguicoso.client.estabelecimento.cardapio.CardapioServiceAsync;
import com.preguicoso.shared.entities.ItemCardapioBean;
import com.preguicoso.shared.utils.MoneyUtils;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.uibinder.client.UiHandler;

public class ItemPedido extends Composite {

	private static ItemPedidoUiBinder uiBinder = GWT
			.create(ItemPedidoUiBinder.class);

	interface ItemPedidoUiBinder extends UiBinder<Widget, ItemPedido> {
	}

	public ItemPedido() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	private final CardapioServiceAsync cardapioService = GWT
			.create(CardapioService.class);

	@UiField
	InlineLabel nome;
	@UiField
	InlineLabel qtde;
	@UiField
	InlineLabel preco;
	@UiField Image imagem;
	@UiField Button remove;
	ItemCardapioBean i = new ItemCardapioBean();

	public ItemPedido(final ItemCardapioBean i) {
		initWidget(uiBinder.createAndBindUi(this));
		nome.setText(i.getNome());
		qtde.setText(i.getQuantidade() + "");
		preco.setText(MoneyUtils.parseString(i.getPreco()));
		imagem.setUrl(i.getImagem());
		this.i = i;
	}
	@UiHandler("remove")
	void onRemoveClick(ClickEvent event) {
		Carrinho.getInstance().removeItem(i);
		Carrinho.getInstance().refreshCarrinho();
	}
}
